package wflow.remote.remote.processor;

import io.netty.channel.Channel;
import io.netty.channel.ChannelFuture;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import wflow.remote.remote.command.Command;
import wflow.remote.remote.command.CommandType;

public class CloseChannelProcessor implements NettyRequestProcessor {
    private final static Logger logger = LoggerFactory.getLogger(EchoProcessor.class);

    @Override
    public void process(Channel channel, Command command) {
        if (command.getType() == CommandType.CLOSE_CHANNEL) {
            ChannelFuture close = channel.close();
            try {
                close.await();
                logger.info("channel {} 关闭", command.getOpaque());
            } catch (InterruptedException e) {
                logger.error("channel {} close fail", command.getOpaque());
                throw new RuntimeException(e);
            }
        }
    }
}
